import http from '@/utils/http.js';
const mapKey = 'QVCBZ-6AIWL-EU7PA-MAEZR-IZN66-EPBWY'
const car = {
	//计算车辆距离方法
	async RoutePlanning({
		commit
	}, data) {
		
		console.log('距离的经纬度',data);
		let from = data.airLatAndLon.lat + ',' + data.airLatAndLon.lng
		let to = data.peopleLatAndLon.latitude + ',' + data.peopleLatAndLon.longitude
		// LatLonList 参数
		return new Promise((resolve, reject) => {
			uni.request({
				url: `https://apis.map.qq.com/ws/distance/v1/matrix?mode=driving`,
				method:'POST',
				data:{
					key:mapKey,
					from,
					to,
				},
				success(res) {
					// 处理
					// from=A,B,C&to=1,2,3
					// 计算结果的二维数组为，以下表格为数组结构示意，行为rows，列为elements：

					// [0,0]：A to 1	[0,1]：A to 2	[0,2]：A to 3
					// [1,0]：B to 1	[1,1]：B to 2	[1,2]：B to 3
					// [2,0]：C to 1	[2,1]：C to 2	[2,2]：C to 3
					console.log(res, 'res.result');
					let result = res.data.result.rows
					let m = 0
					let status = null
					result.map((item,index)=>{
						m = item.elements[0].distance
						status = item.elements[0].status?item.elements[0].status:0
					})
					if(!status){
						console.log("\n %c 距离".concat(m+'米', " %c https://www.uviewui.com/ \n\n"), 'color: #ffffff; background: #3c9cff; padding:5px 0;', 'color: #3c9cff;background: #ffffff; padding:5px 0;');
						resolve(m)
					}else{
						uni.$toast('距离计算失败')
						resolve(m)
					}
				}
			})

		})

	},
	/*
	 * 方法说明: 示例请求方法
	 * author: gaomingzhe
	 * description: 
	 * @param {}   
	 * @return 
	 * @createTime: 2021-12-5 2:52:38 ?F10: PM?
	 */

	//礼宾车 - 背景、咨询
	async getCarBgCover({
		commit
	}, data) {
		let params = data
		const res = await uni.$request('/api/index/car_bg_cover', params)
		if (res.errno != 0) uni.$toast('请求失败！')
		return res.data
	},
	//礼宾车 - 选择机场
	async getAirList({
		commit
	}, data = {
		city_id: 1
	}) {
		let city_id = uni.getStorageSync('city_id')
		let params
		if (city_id) {
			params = {
				city_id
			}
		} else {
			params = data
		}
		const res = await uni.$postRequest('/api/Airport/get_list', params)
		console.log(res)
		if (res.errno != 0) uni.$toast('请求失败！')
		return res.data.info_list
	},
	async getStationList({
		commit
	}, data = {
		city_id: 1
	}) {
		let city_id = uni.getStorageSync('city_id')
		let params
		if (city_id) {
			params = {
				city_id
			}
		} else {
			params = data
		}
		const res = await uni.$postRequest('/api/station/get_list', params)
		console.log(res)
		if (res.errno != 0) uni.$toast('请求失败！')
		return res.data.info_list
	},
	//礼宾车 - 列表、乘客须知
	async getCarList({
		commit
	}, data) {
		let params = data
		const res = await uni.$postRequest('/api/car/get_list', params)
		console.log(res)
		if (res.errno != 0) uni.$toast('请求失败！')
		return res.data
	},
	//礼宾车 - 下单
	async applyOrder({
		commit
	}, data) {
		let params = data
		const res = await uni.$postRequest('/api/apply_order/buildorder', params)
		console.log(res)
		if (res.errno != 0) uni.$toast('请求失败！')
		return res.data
	},
	//礼宾车 - 预计订单费用
	async getDetailSome({
		commit
	}, data) {
		let params = data
		const res = await uni.$getRequest('/api/car/get_detail_some', params)
		console.log(res)
		if (res.errno != 0) uni.$toast('请求失败！')
		return res.data
	},
	//礼宾车 -  预约订单 - 订单详情
	async getOrderDetail({
		commit
	}, data) {
		let params = data
		const res = await uni.$getRequest('/api/apply_order/get_detail', params)
		console.log(res)
		if (res.errno != 0) uni.$toast('请求失败！')
		return res.data
	},
	//礼宾车 -  预约订单 - 支付前
	// card_switch: 1
	// cost_card_cnt: 1
	// integral: 99999999 //总积分
	// integral_price: 32000077 //折扣积分价格
	// price: "40000096.00" //微信支付价格
	// vip: 0
	// vip_id: 8
	async getBeforeDetailSome({
		commit
	}, data) {
		let params = data
		const res = await uni.$getRequest('/api/apply_order/get_detail_some', params)
		console.log(res)
		if (res.errno != 0) uni.$toast('请求失败！')
		return res.data
	},
	//礼宾车 - 预约订单 - 支付订单

	async getPayOrder({
		commit
	}, data) {
		let params = data
		const res = await uni.$getRequest('/api/apply_order/payorder', params)
		console.log(res)
		if (res.errno != 0) uni.$toast('请求失败！')
		return res.data
	},
	//礼宾车 - 预约订单 - 取消订单 /api/apply_order/cancel_order

	async carCancelOrder({
		commit
	}, data) {
		let params = data
		const res = await uni.$getRequest('/api/apply_order/cancel_order', params)
		console.log(res)
		if (res.errno != 0) uni.$toast('请求失败！')
		return res.data
	}
};

export default car;